package com.xiaoma.java8.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>Title: StreamTest </p>
 * <p>Description：描述 </p>
 * <p>Package:com.xiaoma.java8.stream </p>
 * Copyright: Copyright(c) 2020 Travelsky All Rights Reserved Company: Travelsky Software: AIC Date: 2021/3/15 9:58
 *
 * @author maj
 * @version 1.0.0
 */
public class StreamTest {

  public static void main(String[] args) {

    List<User> userList=new ArrayList<>();
    userList.add(new User(null, "pek"));
    userList.add(new User("jerry","ctu"));

    Map<String, List<User>> collect = userList.stream().collect(Collectors.groupingBy(s -> Optional.ofNullable(s.getName()).orElse("")));

    System.out.println(collect);
  }
}
